package com.gamatechno.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.gamatechno.solodestination.HomeFragment;
import com.gamatechno.solodestination.JournalPerjalananFragment;

import com.gamatechno.solodestination.R;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HomeAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater;

	public HomeAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.row_home, null);

		TextView kategori = (TextView) vi.findViewById(R.id.txtKategori);
		ImageView imgKategori = (ImageView) vi.findViewById(R.id.imageKategori);

		HashMap<String, String> artefact = new HashMap<String, String>();
		artefact = data.get(position);

		if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Kuliner")) {
			imgKategori.setImageResource(R.drawable.kuliner_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals(
				"Hotel & Penginapan")) {
			imgKategori.setImageResource(R.drawable.hotel_penginapan_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Wisata")) {
			imgKategori.setImageResource(R.drawable.wisata_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Event")) {
			imgKategori.setImageResource(R.drawable.event_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Belanja")) {
			imgKategori.setImageResource(R.drawable.belanja_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Kerajinan")) {
			imgKategori.setImageResource(R.drawable.kerajinan_icon);
		} else if (artefact.get(HomeFragment.KEY_KATEGORI).equals("Bagikan Foto")) {
			imgKategori.setImageResource(R.drawable.bagikan_foto_icon);
		} 

		Log.d("ARTEFACT", artefact.toString());

		kategori.setText(artefact.get(HomeFragment.KEY_KATEGORI));

		return vi;
	}

}
